#include <A_Config.h>

static const uint8_t battery_empty_bits[] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x03,
    0x01, 0x00, 0x04, 0x01, 0x00, 0x0c, 0x01, 0x00, 0x08, 0x01, 0x00, 0x08,
    0x01, 0x00, 0x08, 0x01, 0x00, 0x08, 0x01, 0x00, 0x0c, 0x01, 0x00, 0x04,
    0xfe, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t battery_quarter_bits[] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x03,
    0x01, 0x00, 0x04, 0x01, 0x00, 0x0c, 0x79, 0x00, 0x08, 0x79, 0x00, 0x08,
    0x79, 0x00, 0x08, 0x79, 0x00, 0x08, 0x01, 0x00, 0x0c, 0x01, 0x00, 0x04,
    0xfe, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t battery_three_quarters_bits[] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x03,
    0x01, 0x00, 0x04, 0x01, 0x00, 0x0c, 0xf9, 0x1f, 0x08, 0xf9, 0x1f, 0x08,
    0xf9, 0x1f, 0x08, 0xf9, 0x1f, 0x08, 0x01, 0x00, 0x0c, 0x01, 0x00, 0x04,
    0xfe, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint8_t battery_full_bits[] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x03,
    0x01, 0x00, 0x04, 0x01, 0x00, 0x0c, 0xf9, 0xff, 0x08, 0xf9, 0xff, 0x08,
    0xf9, 0xff, 0x08, 0xf9, 0xff, 0x08, 0x01, 0x00, 0x0c, 0x01, 0x00, 0x04,
    0xfe, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

static const uint8_t usb_connct_bits[] = {
    0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x3f, 0x00,
    0x80, 0x1d, 0x00, 0x84, 0x08, 0x00, 0xce, 0x00, 0x02, 0xff, 0xff, 0x07,
    0xff, 0xff, 0x07, 0x0e, 0x03, 0x02, 0x04, 0x02, 0x00, 0x00, 0x76, 0x00,
    0x00, 0x7c, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

static const uint8_t battery_chongdian_bits[] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x03,
    0x01, 0x00, 0x04, 0x01, 0x1f, 0x0c, 0x81, 0xf1, 0x08, 0xfd, 0x10, 0x08,
    0xfd, 0x10, 0x08, 0x81, 0xf1, 0x08, 0x01, 0x1f, 0x0c, 0x01, 0x00, 0x04,
    0xfe, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static const uint8_t usb_power_bits[] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00,
    0xc0, 0x40, 0x00, 0x60, 0x40, 0x00, 0x20, 0xc0, 0x0f, 0x3f, 0x40, 0x00,
    0x3f, 0x40, 0x00, 0x20, 0xc0, 0x0f, 0x60, 0x40, 0x00, 0xc0, 0x40, 0x00,
    0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
};

const uint8_t *getBatteryIcon()
{
    int16_t batteryLevel = hal.VCC;
    const uint8_t *batteryIcon;
    if (batteryLevel < 3500)
    {
        batteryIcon = battery_empty_bits;
    }
    else if (batteryLevel < 3700)
    {
        batteryIcon = battery_quarter_bits;
    }
    else if (batteryLevel < 3900)
    {
        batteryIcon = battery_three_quarters_bits;
    }
    else if (batteryLevel < 4300)
    {
        batteryIcon = battery_full_bits;
    }
    else if (batteryLevel > 4400 && hal.USBconnct == true)
    {
        batteryIcon = usb_connct_bits;
    }
    else if (batteryLevel > 4400 && hal.USBconnct == false )
    {
        batteryIcon = usb_power_bits;
    }
    if (hal.isCharging == true && hal.USBconnct == false)
    {
        batteryIcon = battery_chongdian_bits;
    }
    return batteryIcon;
}